home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / xv_pc17.zip / XVIEW.H < prev    next >
C/C++ Source or Header  |  1994-08-03  |  13KB  |  299 lines

  1. #ifndef XVIEWH
  2. #define XVIEWH
  3.  
  4. /*
  5.  Header for the XView-PC graphical user interface. Turbo C/C++/GNU C
  6.  By Antonio Carlos Moreirao de Queiroz - acmq@coe.ufrj.br
  7.  Version 1.0  - 05/07/92
  8.  Version 1.6  - 20/11/93 Large images
  9.  Version 1.6a - 15/04/94 As version 1.6a in Pascal
  10.  Version 1.6b - 30/04/94 The same object files for C or C++
  11.  Version 1.7  - 01/08/94 Compiles also under GNU C (djgpp).
  12.  
  13. The Borland C/C++ version of the package is formed by the files:
  14. "xview.h", "xview.obj": Interface routines.
  15. "mickey.h", "mickey.obj": Mouse support.
  16. "x_make.exe": Interface editor for Pascal and C.
  17.  
  18. To compile a program:
  19. - Use Turbo C++ 1.0 or later version. The object files were generated with
  20.   Borland C++ 3.1.
  21. - Open a project with "mickey.obj", "xview.obj", and the C/C++ source files.
  22. - Turn on the linking with the graphics and floating point libraries.
  23. - Set the memory model to "huge".
  24. - The BGI drivers needed may be (are) also of a different version than the
  25.   ones provided for the Turbo Pascal 7.0 version.
  26.  
  27. The GNU C (djgpp) version of the package is formed by the files:
  28.  
  29. "xview.o": Interface routines.
  30. "mickey.o": Mouse support.
  31.  
  32. The other files are the same of the Borland C/C++ version.
  33.  
  34. Observations about the GNU C (djgpp) version:
  35. - To compile: gcc mickey.o xview.o <c sources> -lbcc -lgrx -lpc -lm -o <name>
  36. - The present version uses the bcc2grx package for full compatibility with
  37.   the Borland C version. GRX functions may also also work for graphics.
  38. - A bug in the "outtextxy" function may cause the text in the windows to
  39.   appear in black over black background. If this happens, the module of the
  40.   bcc2grx library that contains the function must be recompiled. The
  41.   background color when using bitmap fonts shall be changed to GrNOCOLOR
  42.   (function "_otxt_bit" in the module "bccgrx06.c", line 348).
  43.   Recompile the module and substitute it in the "libbcc.a" library with the
  44.   commands (supposing all the files in the same directory):
  45.     gcc -O2 bccgrx06.c -c
  46.     ar -r libbcc.a bccgrx06.o
  47.   Another solution is:
  48.   - Load the compiled program in a binary editor.
  49.   - Search for the sequence: C7 05 EC B8 01 00 00 00 01 00
  50.   - Change to:               C7 05 EC B8 01 00 00 00 00 01
  51.   - Save the changed program.
  52. - Due to the heap management used in djgpp, the reordering of windows can
  53.   cause a fatal error if there is not enough virtual memory (improbable).
  54.   The user must make sure that there are always a few 100Kb of disk space
  55.   free as swap area to completely avoid the problem.
  56. - The "figuresize" function is not available, nor used by the interface.
  57.   The "frame" parameter "areaw" is not available.
  58.   The "getfiguremem" function is different.
  59. - A 386 PC with EGA graphics board is the minimum configuration.
  60. - The GNU C version for DOS (djgpp) is available by anonymous ftp from:
  61.   site: oak.oakland.edu; directory: pub/msdos/djgpp
  62.  
  63. This documentation below covers only the differences between the Pascal and C
  64. versions. See the files "xview_pc.txt" and "xview.int" for more details.
  65.  
  66. General observations:
  67.  
  68. The fields of the "xv_widget" union are acessed in different form.
  69. Examples:
  70. "obj^.x" translates to "obj->x"
  71. "obj^.sel_menu" translates to "obj->v.smenu.sel_menu"
  72. "obj^.gr_out.x1" translates to "obj->v.sframe.gr_out.left"
  73. An idea is to use defines for common fields, or to implement functions to
  74. access the object fields, like the Sun XView "xv_create, "xv_set" and
  75. "xv_get" functions.
  76.  
  77. Memory usage:
  78.  
  79. Each object uses in the heap:
  80. - "sizeof(xv_widget)" bytes.
  81. - The size of the buffers used in "tty" objects, "bsize"+1.
  82. - If a frame that is in the screen and above another, its image area.
  83. No extra memory is allocated for the items of menus and settings.
  84. ********************************************************************************
  85. */
  86.  
  87. /*
  88.  * The variables marked "*" are reserved, and shall not be changed.
  89.  * The variables marked "#" are the ones usually initialized at creation.
  90.  * The others can be freely changed.
  91.  */
  92.  
  93. #ifdef __GNUC__
  94. #include <libbcc.h>
  95. #else
  96. #include <graphics.h>
  97. #endif
  98.  
  99. #define LOC_MOVE 256
  100.   /* event: mouse moved */
  101. #define LOC_DRAG 257
  102.   /* event: mouse moved with pressed buttons */
  103. #define MS_LEFT 1001
  104.   /* event: left button pressed */
  105. #define MS_MIDDLE 1004
  106.   /* event: middle button pressed */
  107. #define MS_RIGHT 1002
  108.   /* event: right button pressed */
  109. #define MS_BOTH 1003
  110.   /* event: right and left buttons pressed */
  111. #define m_itens 20
  112.   /* maximum number of items in menus and settings (only 16 in settings) */
  113. #define m_chars 59
  114.   /* caracters in strings */
  115. #define mrgx 5
  116.   /* lateral and bottom margins in the windows */
  117. #define mrgy 22
  118.   /* upper margin in the windows */
  119.  
  120.   typedef struct widget *Xv_opaque;
  121.   typedef enum { text_field,real_field,int_field } t_field_type;
  122.   typedef struct figstruct {              /* structue for images */
  123.     int blocks;                           /* number of image blocks -1 */
  124.     int fdx, fdy;                         /* dimensions (used by "drawbitmap") */
  125.     unsigned int blocksize,lastblocksize; /* size of the blocks */
  126.     void *v[2001];                        /* allocated until "blocks" */
  127.   } figstruct;
  128.   typedef struct figstruct *ptrfig;       /* imagem pointer */
  129.   typedef void (*xv_handler)(Xv_opaque obj);
  130.   typedef enum { frame,button,textfield,setting,message,canvas,tty,menu } xv_package;
  131.   typedef char xv_label_type[m_chars+1];
  132.   typedef struct widget {
  133.    xv_label_type xv_label;              /* # title */
  134.    int           x,y,dx,dy;             /* # position and size */
  135.    int           fore_color,back_color; /* # colors */
  136.    Xv_opaque     owner;                 /* * frame where the object is */
  137.    Xv_opaque     next;                  /* * next objeto */
  138.    Xv_opaque     menu_name;             /* # associated menu */
  139.    xv_handler    notify_handler;        /* # notify handler */
  140.    xv_handler    event_handler;         /* # event handler */
  141.    void          *client_data;          /* # other associated values */
  142.    xv_package o_type;                   /* * object type */
  143.     union {
  144.      struct { Xv_opaque over;
  145.           Xv_opaque under;        /* * neighbor window frames */
  146.           ptrfig    Pw;           /* * covered image */
  147. #ifdef __TURBOC__
  148.               long int areaw;         /* * image size. Used internally */
  149. #endif
  150.           int       dxmin, dymin; /* # minimum size */
  151.           int       interfere;    /* * used internally */
  152.           int       mapped;       /* * if the window is in the screen */
  153.           int       adjust_exit;  /* # if the window can ba closed with the central mouse button */
  154.           Xv_opaque mouse_obj;    /* # initial location of the mouse (object), or nil */
  155.           struct viewporttype gr_out; } sframe;  /* * viewport */
  156.      struct { int       icon_label;   /* # if "xv_label" is a bitmap file name */
  157.           ptrfig    Pimageb; } sbutton;  /* * button image */
  158.      struct { int       icon_msg;     /* # if "xv_label" is a bitmap filename */
  159.           ptrfig    Pimagem; } smessage; /* *  message image */
  160.      struct { xv_label_type panel_value;    /* # text */
  161.           double panel_real;            /* # corresponding real */
  162.           int   panel_int;              /* # corresponding integer */
  163.           int   min_value, max_value;   /* # integer limits */
  164.           int   value_length;           /* # characters shown */
  165.           t_field_type field_type; } stextfield; /* type */
  166.      struct { int itens_setting;            /* * number of items */
  167.           int      sel_setting;         /* # selection */
  168.           char     *item_setting[m_itens]; /* * item strings */
  169.           int exclusive; } ssetting;       /* # if selection is exclusive */
  170.      struct { int can_xext,can_yext; } scanvas;  /* # if extends to the borders */
  171.      struct { int tty_xext,tty_yext;             /* # " */
  172.           int xc,yc;                   /* * graphical cursors */
  173.           unsigned int bsize;          /* * buffer size */
  174.           unsigned bcsr;               /* * buffer cursor */
  175.           unsigned bstart,tstart,tend; /* * buffer pointers */
  176.           int dxtty;                   /* * effective width */
  177.           char *Pb; } stty;            /* * text buffer */
  178.      struct { int itens_menu;           /* * number of de items */
  179.           int sel_menu;             /* # selected item */
  180.           char *item_menu[m_itens]; /* * item strings */
  181.           Xv_opaque item_submenu[m_itens]; } smenu;  /* # submenus */
  182.    } v;
  183.   } widget;
  184.  
  185.   extern int wallpaper;   /* 0 # if the background is to be retained */
  186.   extern unsigned int normal_bsize;  /* # "bsize" (tty) attributed by "xv_create" */
  187.   extern unsigned int normal_length; /* # "value_length" (textfield) attributed by "xv_create" */
  188.   extern int c_normal;    /* LIGHTGRAY     object background color */
  189.   extern int c_active;    /* GREEN         pressed buttons color */
  190.   extern int c_light;     /* WHITE         lighted corners color */
  191.   extern int c_shadow;    /* BLACK         shadowed corners color */
  192.   extern int c_white;     /* WHITE         default "back_color" */
  193.   extern int c_black;     /* BLACK         default "fore_color" */
  194.   extern int c_overwrite; /* LIGHTRED      overwrite color in textfields */
  195.   extern int c_edit;      /* BLUE          edit color in textfields */
  196.   extern int c_insert;    /* YELLOW        insert color in textfields */
  197.   extern int c_hatch;     /* CYAN          background pattern color */
  198.   extern int type_hatch;        /* XHATCH_FILL  background color */
  199.   extern int use_palette;       /* 1 if bitmap palettes are accepted */
  200.   extern void *normal_client_data; /* NULL attributed to "client_data" by "xv_create" */
  201.   extern int          nlines;   /* * 60, number of lines per image block */
  202.   extern int          insert;   /* 1 if textfields are insert mode */
  203.   extern int          xv_ok;    /* * resultd of the last window operation */
  204.   extern int          xv_end;   /* terminates "xv_main_loop" */
  205.   extern xv_label_type   ulttxt;    /* last text read in textfields */
  206.   extern int          ie_locx,ie_locy;   /* * mouse position relative to object */
  207.   extern int          ie_code;      /* * event code */
  208.   extern int          ie_shiftcode; /* * mouse buttons state */
  209.   extern Xv_opaque    active_w;     /* * the active window frame */
  210.   extern Xv_opaque    active_o;     /* * the active object */
  211.   extern Xv_opaque    w_base;       /* base frame for "xv_create" */
  212.   extern Xv_opaque    o_base;       /* base object for "item_create" */
  213.   extern int redrawing_frame;       /* if a window is being redrawn */
  214.   extern void (*interposer)(void);  /* routine called after each event */
  215.  
  216. #ifdef __cplusplus
  217. extern "C" {
  218. #endif
  219.  
  220. void xv_init(int placa,int modo);
  221. /* General inicialization */
  222.  
  223. Xv_opaque xv_create(xv_package obj_type);
  224. /* Allocates and initializes with default values an object
  225.    Returns its pointer, or NULL if there is not enough memory
  226.    Allocates the "tbuffer" of the "tty"s with Pb=malloc(bsize+1)
  227. */
  228.  
  229. void item_create(const char *txt);
  230. /* Creates an item for a menu or setting
  231.    The items are enumerated from 0 (1 in Pascal)
  232.    No memory is allocated
  233. */
  234.  
  235. void xv_main_loop(Xv_opaque w);
  236. /* Opens a window and initates the loop wait event - process event */
  237.  
  238. void open_window(Xv_opaque w);
  239. /* Opens or activates a window */
  240.  
  241. void close_window(Xv_opaque w);
  242. /* Closes a window, erasing it from the screen */
  243.  
  244. void ttysw_output(Xv_opaque terminal, const char *texto);
  245. /* Writes text to a terminal (tty) */
  246.  
  247. void Back(void);
  248. /* Puts the active window behind the others */
  249.  
  250. void xv_set(Xv_opaque obj, char *new_label);
  251. /* Changes the label of an object, redrawing it. Opens the object window */
  252.  
  253. void menu_show(Xv_opaque obj);
  254. /* Opens a menu at the mouse position */
  255.  
  256. void draw_object(Xv_opaque obj, int complete);
  257. /* Redraws an object */
  258.  
  259. void nothing(Xv_opaque obj);
  260. /* Default "notify_handler" and "event-handler". No action */
  261.  
  262. void nointerpose(void);
  263. /* Default "interposer". No action. */
  264.  
  265. void wait_button(void);
  266. /* Waits until the mouse buttons are released */
  267.  
  268. void drawbitmap(int x,int y,int* dw, int* dh, ptrfig *Pimg, const char *filename);
  269. /* Draws a Window 16 colors bitmap */
  270. /* The filename shall use "/" or "\\" as directory separator */
  271.  
  272. /* The routines below are for operations with large images */
  273.  
  274. #ifdef __TURBOC__
  275. long int figuresize(int x1,int y1,int x2,int y2);
  276. /* Memory needed for an image */
  277. #endif
  278.  
  279. ptrfig getfiguremem(int dw,int dh);
  280. /* Allocates memory for image. "dw" e "dh" are width-1 and height-1
  281. Returns a pointer to a "figstruct" structure, or NULL. Note that the
  282. Pascal version is different */
  283.  
  284. void freefiguremem(ptrfig p);
  285. /* Frees memory allocated for an image */
  286.  
  287. void getfigure(int x1,int y1,int x2,int y2,ptrfig p);
  288. /* Captures an image from the screen */
  289.  
  290. void putfigure(int x,int y,ptrfig p,unsigned int bitblt);
  291. /* Draws a figure in the screen */
  292.  
  293. #ifdef __cplusplus
  294. }
  295. #endif
  296.  
  297. #endif
  298.  
  299.